// pages/defect/craft/params-options/index.js
 
import {
  _update,
  _remove
} from '../../../../api/recipe-composition-type'
 
Component({
  /**
   * 组件的属性列表
   */
  properties: {
     
  },

  /**
   * 组件的初始数据
   */
  data: {
 
    showModal: false,
    dataSource: {},
    _idx: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClose() {
      this.setData({ show: false });
    },
  
    onSelect() {
        this.onModalShow();
    },
    onDelect(){
      wx.showModal({
        title: '是否要删除此参数？',
        success: res=>{
          if(res.confirm){
            _remove(this.data.dataSource, ()=>{
              this.triggerEvent('update')
            })
          }
        }
      })
    },
    open( data, idx){
      this.setData({
        dataSource: data,
        _idx: idx
      })
      const instance = this.selectComponent('#params');
      instance?.initData(data);
      this.onModalShow();
    },
    onModalCancel(){
      this.setData({
        showModal: false
      })
    },
    onModalShow(){
      this.setData({
        showModal: true
      })
    },
    onModalSubmit(event){
      _update({
        adjustmentGlazeTypeId: this.data.dataSource['adjustmentGlazeTypeId'],
        ...event.detail,
        id: this.data.dataSource['id']
      },()=>{
        this.triggerEvent('update');
        this.onModalCancel();
      })
    }
  }
})
